//
//  HttpTest.m
//  EZC_Library
//
//  Created by ellzu on 14-9-25.
//  Copyright (c) 2014年 ellzu. All rights reserved.
//

#import "HttpTest.h"
#import "HttpRequestFactory.h"
#import "HttpRequestDelegate.h"

using namespace EZHttp;

class CHttpTest : public EZHttp::HttpRequestDelegate
{
public:
    
    void onHttpRequestStart(HttpRequest *sender)
    {
        
    }
    void onHttpRequestFinish(HttpRequest *sender)
    {
        
    }
    
    
    void onHttpRequestResponseHeader(HttpRequest *sender)
    {
        NSLog(@"onHttpRequestResponseHeader");
    }
    
    void onHttpRequestProgress(HttpRequest *sender)
    {
        size_t cur = sender->response()->contentCurLen();
        size_t total = sender->response()->contentLen();
        NSLog(@"onHttpRequestProgress:%zu %zu %f",cur,total,cur*1.0/total);
    }
    
//    size_t onHttpRequestReciveContent(HttpRequest *sender,unsigned char* data,size_t dataLen,size_t totalLen);
    
    void onHttpRequestSuccess(HttpRequest *sender)
    {
        NSLog(@"onHttpRequestSuccess");
    }
    void onHttpRequestFail(HttpRequest *sender)
    {
        NSLog(@"onHttpRequestFail");
    }
};


@implementation HttpTest


-(void)testGet
{
//    EZTally::EZAutoreleasePool *pool = new EZTally::EZAutoreleasePool();
    
    EZTallyTemplateAutoPtr<EZHttp::HttpRequest*> ptr =EZHttp::HttpRequestFactory::defaultFactory()->makeRequestAutoPtr();
    EZHttp::HttpRequest *request = ptr.Get();
    request->setUrl("http://bbs.csdn.net/topics/390048823");
    request->setUrl("http://www.baidu.com");
    request->setDownLoadPath("/Users/ellzu/Desktop/mydownload.txt");
    request->setTempPath("/Users/ellzu/Desktop/mydownload.temp.txt");
    CHttpTest *cht = new CHttpTest();
    request->setDelegate(cht);
    request->setProgressCount(1000);
    request->startSync();
    
//    char buffer[1024];
//    request->response()->copyContent((unsigned char*)&buffer, 1024, 0);
//    NSString *str = [NSString stringWithFormat:@"%s",buffer];
//    
//    NSLog(@"%@",str);

//    pool->Release();
}

@end
